package com.security.antitheft.module;

import android.content.Context;
import android.content.SharedPreferences;

public class ShareSetting {

	private static String PREF_SERVER = "serverto";
	private static String PREF_PASSWD = "passwd";
	
	private static String PREF_EN_CALLLOG = "enable_calllog";
	private static String PREF_EN_CONTACT = "enable_contact";
	private static String PREF_EN_LOCATION = "enable_location";
	private static String PREF_EN_PICS = "enable_pics";
	private static String PREF_EN_SMS = "enable_sms";
	
	
	private static String PREF_LID_CONTACT = "lastcontactid";
	private static String PREF_LID_PICS = "lastpicsid";
	private static String PREF_LID_SMS = "lastsmsid";
	
	//k-review
	private static String LOCK_FROM_REMOTE = "lock_from_remote";
	private static String LOCK_RELEASE = "lock_release";
	private static String DEVICE_INFO = "device_info";
	private static String ERASE_STATE = "erase_state";
	
	private static String PREF_NAME = "securitycollector";
	
	
	public static void setPassword(Context c, String pwd) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putString(PREF_PASSWD, pwd);
		editor.commit();
	}
	
	public static String serverTo(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		
		//return preferences.getString(PREF_SERVER, "android.is-saved.org:8008");
		return preferences.getString(PREF_SERVER, "android.is-saved.org:8009");
		//return preferences.getString(PREF_SERVER, "10.70.5.46:8080/test/admin_panel/mobile/collector.php");
	}
	
	public static void setServerTo(Context c, String address) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putString(PREF_SERVER, address);
		editor.commit();
	}
	
	public static long lastSms(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		return preferences.getLong(PREF_LID_SMS, -1);
	}
	public static void setLastSms(Context c, long lasteId) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putLong(PREF_LID_SMS, lasteId);
		editor.commit();
	}
	
	public static long lastPics(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		return preferences.getLong(PREF_LID_PICS, -1);
	}
	public static void setLastPics(Context c, long lasteId) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putLong(PREF_LID_PICS, lasteId);
		editor.commit();
	}
	
	public static long lastContact(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		return preferences.getLong(PREF_LID_CONTACT, -1);
	}
	public static void setLastContact(Context c, long lasteId) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putLong(PREF_LID_CONTACT, lasteId);
		editor.commit();
	}
	
	public static boolean isEnableCallLog(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		return preferences.getBoolean(PREF_EN_CALLLOG, true);
	}

	public static boolean isEnableContact(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		return preferences.getBoolean(PREF_EN_CONTACT, true);
	}
	
	public static boolean isEnableLocation(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		return preferences.getBoolean(PREF_EN_LOCATION, true);
	}
	
	public static boolean isEnablePics(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		return preferences.getBoolean(PREF_EN_PICS, true);
	}
	
	public static boolean isEnableSms(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		return preferences.getBoolean(PREF_EN_SMS, true);
	}
	
	//k-review
	//deviceinfo
	public static boolean GetDeviceInfo(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		return preferences.getBoolean(DEVICE_INFO, true);
	}
	public static void SetDeviceInfo(Context c, boolean deviceinfo) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putBoolean(DEVICE_INFO, deviceinfo);
		editor.commit();
	}
	
	//decide lock the device from remote
	public static boolean GetLockFromRemote(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		return preferences.getBoolean(LOCK_FROM_REMOTE, false);
	}
	public static void SetLockFromRemote(Context c, boolean lockFromRemote) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putBoolean(LOCK_FROM_REMOTE, lockFromRemote);
		editor.commit();
	}
	
	//lock release
	public static boolean GetLockRelease(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		return preferences.getBoolean(LOCK_RELEASE, false);
	}
	public static void SetLockRelease(Context c, boolean lockRelease) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putBoolean(LOCK_RELEASE, lockRelease);
		editor.commit();
	}
	
	//erase flag
	public static boolean GetEraseState(Context c) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		return preferences.getBoolean(ERASE_STATE, false);
	}
	public static void SetEraseState(Context c, boolean eraseState) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putBoolean(ERASE_STATE, eraseState);
		editor.commit();
	}
	
	public static void setServiceStatus(Context c, boolean enableCallLog, boolean enableContact, boolean enableLocation, boolean enableSms, boolean enablePics) {
		SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putBoolean(PREF_EN_CALLLOG, enableCallLog);
		editor.putBoolean(PREF_EN_CONTACT, enableContact);
		editor.putBoolean(PREF_EN_LOCATION, enableLocation);
		editor.putBoolean(PREF_EN_SMS, enableSms);
		editor.putBoolean(PREF_EN_PICS, enablePics);
		editor.commit();
	}
	
}
